package _1_4_regex;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 正则表达式 示例, 见 java-work-experience 项目
 */
public class MatchTest {

    @Test
    public void StringMatch() {
        System.out.println("knowledge is power".matches("know"));       // false
        System.out.println("knowledge is power".matches("know.*"));     // true
        System.out.println("knowledge is power".matches(".*know.*"));   // true
    }

    @Test
    public void getMatchString() {
        String origin = "12:34,45:78,98:12";
        String[] split = origin.split("[:,]");
        System.out.println(Arrays.asList(split));


        List<String> list = new ArrayList<String>();
        Pattern pattern = Pattern.compile(":(\\d{2}?)");// 匹配的模式
        Matcher m = pattern.matcher(origin);
        while (m.find()) {
            list.add(m.group(1));
        }
        System.out.println(list);
    }

}
